<template>
    <h2 style="text-align: center">添加投资项目</h2>
    <table class="table table-bordered">
        <tr>
                <td>投资项目名称</td>
                <td><input type="text"  v-model="info.I_Name" placeholder="请输入投资项目名称"></td>
            </tr>
            <tr>
                <td>投资项目总额度</td>
                <td><input type="text" v-model="info.I_Budget"  placeholder="请输入投资项目总额度"></td>
            </tr>
        <tr>
            <td colspan="2">
            <input type="button" @click="addInvest" value="添加" >
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';


const router = useRouter();

const info = ref({
    I_Name: '',
    I_Budget: '',
    
});

const addInvest = () => {
    axios.post('http://localhost:58004/api/invest/AddInvestInfo',info.value)
    .then((res) => {
        if (res.data>0) {
            alert('添加成功');
            router.push('/SelInvest');
        } 
        else if(res.data==-1)
         {
            alert('项目已存在');
            return;
        }
        else
         {
            alert('添加失败');
        }
    })
    .catch((err) => {
        console.log(err);
    });
};

</script>
